<?php
class AsyMysql{
    public $db = null;
    public $dbConfig = [];
    public function __construct(){
        $this->db = new swoole_mysql;
        $this->dbConfig = [
            'host' => '192.168.85.100',
            'port' => 3306,
            'user' => 'test',
            'password' => 'test',
            'database' => 'operation',
            'charset' => 'utf8', //指定字符集
            'timeout' => 2,  // 可选：连接超时时间（非查询超时时间），默认为SW_MYSQL_CONNECT_TIMEOUT（1.0）
        ];
    }

    public function update(){

    }

    public function add(){

    }
    public function execute($id,$username){
        echo "swoole-connect";
        $this->db->connect($this->dbConfig,function($db,$result){
            if($result === false){
                var_dump($db->connect_error);
            }

            $sql = "select * from mylock where id = 1";
            $db->query($sql,function($db,$result){
                if($result === false){
                    //todo
                }elseif($result === true){

                }else{
                    print_r($result);
                }
                $db->close();
            });
        });
        return true;
    }

}
$my = new AsyMysql();
$flag = $my->execute(1,'tim');
var_dump($flag);
echo "start ....".PHP_EOL;